import * as vscode from "vscode";

export async function createWebViewer(extensionUri: vscode.Uri) {
  const panel = vscode.window.createWebviewPanel(
    "copy_code",
    "便捷载荷",
    vscode.ViewColumn.One,
    {
      enableScripts: true,
      // localResourceRoots: [vscode.Uri.file(path.join(extensionUri.fsPath, 'resource'))]
    }
  );
  const webviewPath = vscode.Uri.joinPath(
    extensionUri,
    "resource",
    "WebView.html"
  );

  try {
    const webviewByte = await vscode.workspace.fs.readFile(webviewPath);
    const webviewFile = new TextDecoder("utf-8").decode(webviewByte);
    panel.webview.html = webviewFile;
  } catch (err) {
    console.error(`Error reading WebView.html\n ${err}`);
  }

  return panel;
}
